package com.huafeng.model.base;

import com.huafeng.model.enums.ResultCodeEnum;
import lombok.Data;

/**
 * @author 花风
 * @date 2023/8/15 20:40
 * @Description 前端统一返回结果类
 */
@Data
public class Result {
    private String message;
    private Integer code;
    private Object data;

    public Result(ResultCodeEnum resultCodeEnum){
        this(resultCodeEnum,null);
    }

    public Result(ResultCodeEnum resultCodeEnum,Object data){
        this(resultCodeEnum.getMessage(),resultCodeEnum.getCode(),data);
    }

    public Result(String message,Integer code){
        this(message,code,null);
    }

    public Result(String message,Integer code,Object data){
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public static Result ok(){
        return new Result(ResultCodeEnum.SUCCESS);
    }

    public static Result ok(Object data){
        return new Result(ResultCodeEnum.SUCCESS,data);
    }

    public static Result fail(){
        return new Result(ResultCodeEnum.FAIL);
    }

    public static Result fail(Object data){
        return new Result(ResultCodeEnum.FAIL,data);
    }
}
